import java.util.Stack;

public class MinStack {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    private int minVal;

    public MinStack() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int val) {
        if (stack1.isEmpty()) {
            stack2.push(stack1.push(val));
        } else {
            int ret = stack1.push(val);
            if (ret <= stack2.peek()) {
                stack2.push(ret);
            }
        }
    }


    public void pop() {
        if(stack1.isEmpty()) {
            return;
        }
        int tmp = stack1.pop();
        if (tmp == stack2.peek()) {
            stack2.pop();
        }
    }

    public int top() {
        if(stack1.isEmpty()) {
            return -1;
        }
        return stack1.peek();
    }

    public int getMin() {
        if(stack2.isEmpty()) {
            return -1;
        }
        return stack2.peek();
    }
}

class Test {
    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(0);
        minStack.push(1);
        minStack.push(0);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());

    }
}
